#include<iostream>
#include <sys/time.h>
#include <unistd.h>
using namespace std;
const int N = 10005;
float nums[N][N];
float v[N];
float sum[N];
void products1(int n) {
    for (int i = 1; i <= n; ++i) {
        sum[i] = 0.0;
        for (int j = 1; j <= n; ++j)
            sum[i] += nums[j][i] * v[j];
    }
}
void products2(int n) {
    for (int i = 1; i <= n; ++i)
        sum[i] = 0.0;
    for (int j = 1; j <= n; ++j)
        for (int i = 1; i <= n; ++i)
            sum[i] += nums[j][i] * v[j];
}
int main() {
    for (int i = 1; i < N; ++i)
        for (int j = 1; j < N; ++j)
            nums[i][j] = i + j;
    for (int i = 1; i <= N; ++i)v[i] = i;
    timeval start, end;
    long long time_used;
    int step = 10, cnt = 0;
    cout << "---------------the first way------------";
    for (int n = 10; n <= 5000; n += step) {
        gettimeofday(&start, NULL);
        do {
            products1(n);
            gettimeofday(&end, NULL);
            ++cnt;
            time_used = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
            time_used /= 1000;
        } while (time_used < 2);
        printf("%d & %d & %d\\\\\n",cnt,n,time_used);
        cnt = 0;
        if (n == 100)step = 100;
        if(n==1000)step=1000;
    }
    step = 10, cnt = 0;
    cout << "----------------the second way-----------";
    for (int n = 10; n <= 5000; n += step) {
        gettimeofday(&start, NULL);
        do {
            products1(n);
            gettimeofday(&end, NULL);
            ++cnt;
            time_used = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
            time_used /= 1000;
        } while (time_used < 2);
        printf("%d & %d & %d\\\\\n",cnt,n,time_used);
        cnt = 0;
        if (n == 100)step = 100;
        if(n==1000)step=1000;
    }
}   

